<template>
  <Card title="志愿服务 - 审核">
    <Card :bordered="false">
      <Select v-model="querySaveVolunteersSignBO.cuSignState" style="width: 150px">
        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      <Button type="primary" @click="query" style="margin-left: 15px">查询</Button>
    </Card>
    <Table border stripe ref="selection" size="small" :columns="columns" :data="nowData">
      <template slot-scope="{ row, index }" slot="action">
        <div  v-if="row.cuSignState == 0">
          <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">审核</Button>
          <Button type="error" size="small" @click="remove(row)">驳回</Button>
        </div>
        <div v-if="row.cuSignState != 0">
          <span>无需操作</span>
        </div>
        <Modal
          v-model="modal1"
          title="提示"
          @on-ok="okDel">
          <p>确定要审核通过吗?</p>
        </Modal>
        <Modal
          v-model="modal2"
          title="提示"
          @on-ok="okDel2">
          <p>确定要驳回吗?</p>
        </Modal>
      </template>

    </Table>
    <Page :total="dataCount" :page-size="querySaveVolunteersSignBO.size" @on-change="changePage" @on-page-size-change="_nowPageSize"
          show-total show-sizer show-elevator/>
  </Card>
</template>

<script>
export default {
  name: 'volunteers-sign',
  data () {
    return {
      auditDate: {},
      modal1: false,
      modal2: false,
      dataCount: 0,
      nowData: [],
      columns: [
        {
          title: '序号',
          key: 'cuVolunteersSignId'
        },
        {
          title: '用户名',
          key: 'cuUsername'
        },
        {
          title: '注册人姓名',
          key: 'cuVolunteersName'
        },

        {
          title: '性别',
          key: 'cuVolunteersSex',
          render: (h, params) => {
            if (params.row.cuVolunteersSex == 0) {
              return h('span', '女')
            } else {
              return h('span', '男')
            }
          }

        },
        {
          title: '活动标题',
          key: 'cuVolunteersTitle'
        },
        {
          title: '状态',
          key: 'cuSignState',
          render: (h, params) => {
            if (params.row.cuSignState == 0) {
              return h('span', '未审核')
            } else if (params.row.cuSignState == 1) {
              return h('span', '已审核')
            } else {
              return h('span', '已驳回')
            }
          }
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      cityList: [
        {
          value: 0,
          label: '未审核'
        }, {
          value: 1,
          label: '已审核'
        }, {
          value: 2,
          label: '已驳回'
        }
      ],
      volunteersAuditBO: {
        cuVolunteersSignId: null,
        cuVolunteersUserId: this.$store.state.user.userAll.cuAdminId,
        cuSignState: 0
      },
      querySaveVolunteersSignBO: {
        cuSignState: 0,
        current: 1,
        size: 10,
        cuVolunteersUserId: this.$store.state.user.userAll.cuAdminId
      }
    }
  },
  methods: {
    okDel2 () {
      this.volunteersAuditBO.cuVolunteersSignId = this.auditDate.cuVolunteersSignId
      this.volunteersAuditBO.cuSignState = 2
      this.$axios_supermall.post('/cu-volunteers-sign/volunteersAudit', this.volunteersAuditBO).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.success('驳回成功')
          this.query()
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    okDel () {
      this.volunteersAuditBO.cuVolunteersSignId = this.auditDate.cuVolunteersSignId
      this.volunteersAuditBO.cuSignState = 1
      this.$axios_supermall.post('/cu-volunteers-sign/volunteersAudit', this.volunteersAuditBO).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.success('审核成功')
          this.query()
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    changePage (index) {
      this.querySaveVolunteersSignBO.size = index
    },
    _nowPageSize (index) {
      this.querySaveVolunteersSignBO.current = index
      this.query()
    },
    query () {
      this.$Loading.start()
      this.$axios_supermall.post('/cu-volunteers-sign/selectPageAll', this.querySaveVolunteersSignBO).then(resp => {
        if (resp.data.code == 0) {
          let data = resp.data.data
          this.nowData = data.records
          this.dataCount = data.total
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    show (row) {
      this.auditDate = row
      this.modal1 = true
    },
    remove (row) {
      this.auditDate = row
      this.modal2 = true
    }
  },
  mounted () {
    this.query()
  }
}
</script>

<style scoped>

</style>
